package com.gzz.orchid.context.application.rbac.impl;

import com.gzz.orchid.common.core.tuple.Option;
import com.gzz.orchid.context.application.rbac.IRoleHandler;
import com.gzz.orchid.context.application.rbac.convert.RoleConverter;
import com.gzz.orchid.context.application.rbac.pojo.RoleDto;
import com.gzz.orchid.context.application.rbac.pojo.RoleVo;
import com.gzz.orchid.context.application.rbac.queries.RoleQuery;
import com.gzz.orchid.context.infrastructure.persistence.entity.sys.SysRolePo;
import com.gzz.orchid.context.infrastructure.persistence.mapper.sys.SysPermissionMapper;
import com.gzz.orchid.context.infrastructure.persistence.mapper.sys.SysRoleMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;


/**
 * @author higmd
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class RoleHandler implements IRoleHandler {
    private final SysRoleMapper mapper;
    private final SysPermissionMapper permissionMapper;

    @Override
    public List<RoleDto> listByPager(RoleQuery query) {
//        QueryWrapper queryWrapper = new QueryWrapper();
//        return mapper.paginateAs(1, 100
//                , queryWrapper, RoleDto.class);
        return null;
    }

    @Override
    public List<RoleDto> list(RoleQuery query) {
//        var condition = QueryCondition.create(SYS_ROLE_PO.STATUS, "=", "3");
        List<SysRolePo> poList = null;
        //mapper.selectListByCondition(condition);
        return poList.stream()
                .map(RoleConverter.INSTANCE::mapDto)
                .toList();
    }

    @Override
    public RoleVo detail(Long id) {
//        SysRolePo po = mapper.selectOneById(id);
//        List<Permission> permissions = Optional.ofNullable(po)
//                .map(item -> permissionMapper.selectListByCondition(QueryCondition.create(SYS_PERMISSION_PO.ROLE_CODE, "=", item.getCode())))
//                .map(item -> item.stream()
//                        .map(perm -> Permission.of(perm.getModuleCode(), perm.getRoleCode(), perm.getPurview()))
//                        .collect(Collectors.toList()))
//                .orElse(null);
//        return Optional.ofNullable(po)
//                .map(item -> RoleConverter.INSTANCE.mapVo(po, permissions))
//                .orElse(null);
        return null;
    }

    @Override
    public List<Option<String>> options() {
//        List<SysRolePo> modulePos = mapper.selectListByCondition(QueryCondition.create(SYS_ROLE_PO.STATUS, "=", Status.ENABLED.getValue()));
//        return modulePos.stream()
//                .map(item -> Option.of(item.getName(), item.getCode()))
//                .toList();
        return List.of();
    }
}
